<%--
  Created by IntelliJ IDEA.
  User: 倪继文
  Date: 2017/6/19
  Time: 17:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%@ include file="/common/meta.jsp"%>
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">


    <script>
        var selectidMain = null;


        $(function() {
            var height = findDimensions_height();
            $("#l_datagrid").height(height - 50);

            $('#l_datagrid').datagrid(
                {
                    url:'/SysHospitalBranch/getAllHospitalBranch?rdm='+ parseInt(Math.random()*100000),
                    method:'get',
                    rownumbers:true,
                    singleSelect:true,
                    autoRowHeight:false,
                    remoteSort:false,
                    columns: [
                        [
                            { field: 'id', title: 'ID', hidden: true },
                            { field: 'xh', title: '序号', width: '40px', align: 'left',sortable:true, halign: 'center' },

                            { field: 'name', title: '名称', width: '150px', align: 'left', sortable:true,halign: 'center'},
                            { field: 'address', title: '名称', width: '150px', align: 'left', sortable:true,halign: 'center'}


                        ]
                    ],
                    onClickRow: function(index,row) {
                        var id = row.id;
                        selectidMain = row.id;
                        loadKeshiByYqID(selectidMain);
                        loadNoKeshiByYqID(selectidMain);
                    }
                });
            $("#r_datagrid").height(height-50);


            $('#r_datagrid').datagrid(
                {
                    url:'',
                    method:'get',
                    rownumbers:true,
                    singleSelect:true,
                    autoRowHeight:false,
                    remoteSort:false,
                    columns: [
                        [
                            { field: 'id', title: 'ID', hidden: true },
//                            { field: 'xh', title: '序号', width: '40px', align: 'left',sortable:true, halign: 'center' },
                            { field: 'code', title: '科室代码', width: '150px', align: 'left', sortable:true,halign: 'center'},
                            { field: 'name', title: '科室名称', width: '150px', align: 'left', sortable:true,halign: 'center'},
                            { field: 'operate', title: '操作', width: '80px', align: 'left', halign: 'center',
                                formatter:function(value,row,index){

                                    var str = '<button type=\'button\' class=\'btn btn-danger bi-glyphicon\' onclick="DelYqKs(\'' + row.id + '\')"><span class=\'glyphicon glyphicon glyphicon-remove\'></span></button>';
                                    return str;
                                }
                            }


                        ]
                    ],
                    onClickRow: function(index,row) {


                    }
                });

            $("#r2_datagrid").height(height-50);


            $('#r2_datagrid').datagrid(
                {
                    url:'',
                    method:'get',
                    rownumbers:true,
                    singleSelect:true,
                    autoRowHeight:false,
                    remoteSort:false,
                    columns: [
                        [
                            { field: 'id', title: 'ID', hidden: true },
//                            { field: 'xh', title: '序号', width: '40px', align: 'left',sortable:true, halign: 'center' },
                            { field: 'code', title: '科室代码', width: '150px', align: 'left', sortable:true,halign: 'center'},
                            { field: 'name', title: '科室名称', width: '150px', align: 'left', sortable:true,halign: 'center'},
                            { field: 'operate', title: '操作', width: '80px', align: 'left', halign: 'center',
                                formatter:function(value,row,index){

                                    var str = '<button type=\'button\' class=\'btn btn-danger bi-glyphicon\' onclick="AddYqKs(\'' + row.id + '\')"><span >添加</span></button>';
                                    return str;
                                }
                            }


                        ]
                    ],
                    onClickRow: function(index,row) {


                    }
                });


        });

        function addKeshi(){
            if(selectidMain==null){
                layerInfo("请选择表单！");
            }else{
                layeropen(600, 450, "科室选择", "/V_SysKeShi/toSelYqKs");
            }
        }

        function DelYqKs(id) {
            layerConfirm("是否确定删除?",function () {
                var url = '${ctx}/SysHospitalBranchKs/delete?id=' + id;
                $.ajax({
                    type: 'post',
                    url: url,
                    dataType: "json",
                    success: function (data) {
                        if (data.success == true) {
                            loadNoKeshiByYqID(selectidMain);
                            loadKeshiByYqID(selectidMain);
                        } else {
                            alert(data.msg);
                        }
                    }
                });
            });
        }


        function AddYqKs(id) {
            if (selectidMain == null) {
                layerInfo("请选择表单！");

                return;
            }

            $.ajax({
                type: 'post',
                url: '/SysHospitalBranchKs/addyqks?ksid='+id+'&yqId='+selectidMain,
                dataType: "json",
                success: function (data) {
                    if (data.success == true) {
                        loadNoKeshiByYqID(selectidMain);
                        loadKeshiByYqID(selectidMain);
                        layerMsg(data.msg);
                    } else {
                        layerError(data.msg);
                    }
                }
            });


        }
        function addXgks(id,name){

            debugger;
            if(id!=''&&id!=null){
                $.ajax({
                    type: 'post',
                    url: '/SysHospitalBranchKs/saveHospitalBranchKs?ksids='+id+'&yqId='+selectidMain,
                    dataType: "json",
                    success: function (data) {
                        if (data.success == true) {
                            loadKeshiByYqID(selectidMain);
                            layerMsg(data.msg);
                        } else {
                            layerError(data.msg);
                        }
                    }
                });
            }
        }

        function loadKeshiByYqID(yqid) {
            $('#r_datagrid').datagrid(
                {
                    url: '/SysHospitalBranchKs/getKsByYqId?yqid='+yqid+'&rdm=' + parseInt(Math.random()*100000)
                });
        }

        function loadNoKeshiByYqID(yqid) {
            $('#r2_datagrid').datagrid(
                {
                    url: '/SysHospitalBranchKs/getNoKsByYqId?yqid='+yqid+'&rdm=' + parseInt(Math.random()*100000)
                });
        }

    </script>

</head>
<body>

<div class="navheader form-inline" style="padding:0 5px;height:40px;">
    <div class=" form-group">
        <%--<label for="serach"style="padding:5px 10px 0px 20px;">查询</label>--%>
        <%--<input type="text" id="serach" class="form-control"placeholder="名称、拼音码" />--%>
        <%--<button type="button" class="btn btn-success bi-btn-search" onclick="search()">--%>
            <%--<span class="glyphicon glyphicon glyphicon-search"></span>--%>
        <%--</button>--%>
    </div>
    <div class="btn-group-right">
        <div class="btn-group "  role="group">
            <button type="button" class="btn btn-default bi-btn-width90" onclick="refresh()">刷新</button>
            <button type="button" class="btn btn-default bi-btn-width90" onclick="addKeshi()">选择科室</button>

        </div>
    </div>
</div>

<div style="margin:0 5px; overflow: hidden;" >
    <!--左边表格-->
    <div style="width:30%;float:left;display:inline-block;padding-right:5px;border-right:1px dotted #ccc;" >
        <table id="l_datagrid"class="datagrid"></table>

    </div>

    <div style="width:70%;float:right;display:inline-block;">
        <!--右边表格 -->
        <div style="width:50%;float:left;display:inline-block;">
            <table id="r_datagrid" class="datagrid"></table>
        </div>

        <!--右边表格 -->
        <div style="width:50%;float:right;display:inline-block;padding-left:5px;">
            <table id="r2_datagrid" class="datagrid"></table>
        </div>
    </div>

</div>



</body>
</html>
